#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import re
from fastapi import FastAPI
from starlette.requests import Request
from starlette.templating import Jinja2Templates


app = FastAPI()


# 设置模板存放路径
template = Jinja2Templates(directory='templates')


@app.get('/')
async def index(request: Request):
    return template.TemplateResponse('index.html', {'request': request})


@app.get("/api/v1/findall")
async def findall(pattern: str, string: str, flags: str = ""):
    if (not pattern) or (not string):
        return "请输入字符串和正则表达式"

    return str(re.findall(pattern, string))
